package com.veepeak.server.api.app;

import com.alibaba.fastjson.JSONObject;
import com.veepeak.server.common.JSONResult;
import com.veepeak.server.domain.DtcCommand;
import com.veepeak.server.domain.ModelCommand;
import com.veepeak.server.domain.VehicleMake;
import com.veepeak.server.domain.VehicleModel;
import com.veepeak.server.repository.VehicleMakeRepository;
import com.veepeak.server.service.DtcCommandService;
import com.veepeak.server.service.ModelCommandService;
import com.veepeak.server.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/vehicle")
@Api(description = "OBD命令接口")
public class VehicleApi {
    @Autowired
    private VehicleService vehicleService;

    @ApiOperation(value = "查询车辆制造商接口", notes = "")
    @GetMapping(value = "/make")
    public JSONObject getDTC(){
        try {
            List<VehicleMake> makeList = vehicleService.makeList();
            return JSONResult.toSuccessJson(makeList,"");
        } catch (Exception e) {
            e.printStackTrace();
            return JSONResult.toFailureJson(e.getMessage());
        }
    }

    @ApiOperation(value = "根据makeId查询车辆型号", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "makeId", value = "makeId", paramType = "path", required = true, dataTypeClass = String.class),
    })
    @GetMapping(value = "/model/{makeId}")
    public JSONObject getModel(@PathVariable String makeId){
        try {

            List<VehicleModel> modelList = vehicleService.modelList(makeId);
            return JSONResult.toSuccessJson(modelList,"");
        } catch (Exception e) {
            return JSONResult.toFailureJson(e.getMessage());
        }
    }
}
